import {createContext, useReducer} from "react"


export const ColorContext = createContext({})
export const UPDATE_COLOR = "UPDATE_COLOR"
const reduce = (state,action) => {
    switch(action.type){
        case "UPDATE_COLOR":
            return action.color;
        default:
            return state;
    }
}

export const Colors = props => {
    const [color,dispatch] = useReducer(reduce,"blue")
    // 将状态和改变状态的方法放到容器中
    return (
        <ColorContext.Provider value={{color,dispatch}}>
            {props.children}
        </ColorContext.Provider>
    )
}